package com.xxxx.seckill.rabbitmq;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 消息发送者
 *
 * @author: LC
 * @date 2022/3/7 7:42 下午
 * @ClassName: MQSender
 */
@Service
@Slf4j
public class MQSender {

    @Autowired
    private RabbitTemplate rabbitTemplate;


    /**
     * 发送秒杀消息
     *
     * @param message 消息体
     */
    public void sendSeckillMessage(String message) {
        log.info("发送消息" + message);
        rabbitTemplate.convertAndSend("seckillExchange", "seckill.message", message);
    }

    /**
     * 发送支付订单的消息
     * @param message 消息体
     */
    public void sendPayOderMessage(String message){
        log.info("发送支付订单的消息：[{}]",message);
        rabbitTemplate.convertAndSend("payExchange","pay.message",message);
    }

    /**
     * 发送取消订单的消息
     * @param message 消息体
     */
    public void sendCancelOderMessage(String message){
        log.info("发送取消订单的消息：[{}]",message);
        rabbitTemplate.convertAndSend("cannelExchange","cancel.message",message);
    }


}
